<template>
  <div class="businessUnit">
    <topBar :title="title"></topBar>
    <div class="connet">
      <div class="text">
        <div>
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ monthFrom }}</div>
          </div>
          <p><span class="circle"></span>{{ increaseFrom }}</p>
          <p><span class="circle"></span>{{ downFrom }}</p>
        </div>
        <div v-if="allFrom">
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ allFrom }}</div>
          </div>
          <p><span class="circle"></span>{{ downText }}</p>
          <p><span class="circle"></span>{{ downThree }}</p>
        </div>
        <div v-if="allBudget">
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ allBudget }}</div>
          </div>
          <p><span class="circle"></span>{{ frontBudget }}</p>
          <p><span class="circle"></span>{{ laterBudget }}</p>
        </div>
      </div>
      <div class="table">
        <el-table
          :data="tableData"
          border
          :cell-style="cellStyle"
          :header-cell-style="headerStyle"
        >
          <el-table-column
            label="经营单元"
            prop="areaName"
            align="center"
            :style="{ padding: '0px' }"
          ></el-table-column>
          <el-table-column
            v-for="(item, index) in tableTitle"
            :label="item"
            :key="index"
            align="center"
            :style="{ padding: '0px' }"
          >
            <template slot-scope="scope">
              <div v-if="tableTitle.length == 8">
                <span v-if="index < 4">{{ scope.row["fee" + index] }}</span>
                <span v-else>{{ scope.row["fee" + (index + 2)] }}<span v-if="(index == 7 || index == 5) && scope.row['fee' + (index + 2)]">%</span></span>
              </div>
              <div v-if="tableTitle.length == 9">
                <span v-if="index < 5">{{ scope.row["fee" + index] }}</span>
                <span v-else>{{ scope.row["fee" + (index + 1)] }}<span v-if="(index == 8 || index == 6)  && scope.row['fee' + (index + 1)]">%</span></span>
              </div>
              <div v-if="tableTitle.length == 10">
                <span>{{ scope.row["fee" + index] }}<span v-if="(index == 9 || index == 7)  && scope.row['fee' + index]">%</span></span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "./topBar";
import { stepUnitgrouth } from "@/api/codeIncome/analysis";
export default {
  name: "businessUnit",
  components: {
    topBar,
  },
  props: {
    searchData: {
      type: Object,
      default: {},
    },
  },
  watch: {
    searchData: {
      handler(newName) {
          this.getData();
      },
      deep: true,
    },
  },
  data() {
    return {
      title: "台阶收入 – 经营单元增长情况",
      monthFrom: "",
      increaseFrom: "",
      downFrom: "",
      allFrom: "",
      downText: "",
      downThree: "",
      allBudget: "",
      frontBudget: "",
      laterBudget: "",
      tableData: [],
      tableTitle: [],
    };
  },
  created() {},
  mounted() {
    this.getData();
  },
  methods: {
    cellStyle({ row, column, rowIndex, columnIndex }) {
        if (row.color7 == "MHB_TOP_0" && columnIndex == this.tableTitle.length - 2) {
          return "background: #5A8AC6;padding:0;color:black";
        } else if (row.color7 == "MHB_TOP_1" && columnIndex == this.tableTitle.length - 2) {
          return "background: #7BA1D2;padding:0;color:black";
        } else if (row.color7 == "MHB_TOP_2" && columnIndex == this.tableTitle.length - 2) {
          return "background: #D9E4F3;padding:0;color:black";
        } else if (row.color7 == "MHB_OFF_0" && columnIndex == this.tableTitle.length - 2) {
          return "background: #F8696B;padding:0;color:black";
        } else if (row.color7 == "MHB_OFF_1" && columnIndex == this.tableTitle.length - 2) {
          return "background: #F98E95;padding:0;color:black";
        } else if (row.color7 == "MHB_OFF_2" && columnIndex == this.tableTitle.length - 2) {
          return "background: #FABCBE;padding:0;color:black";
        } else if (row.color9 == "QHB_TOP_0" && columnIndex == this.tableTitle.length) {
          return "background: #5A8AC6;padding:0;color:black";
        } else if (row.color9 == "QHB_TOP_1" && columnIndex == this.tableTitle.length) {
          return "background: #7BA1D2;padding:0;color:black";
        } else if (row.color9 == "QHB_TOP_2" && columnIndex == this.tableTitle.length) {
          return "background: #D9E4F3;padding:0;color:black";
        } else if (row.color9 == "QHB_OFF_0" && columnIndex == this.tableTitle.length) {
          return "background: #F8696B;padding:0;color:black";
        } else if (row.color9 == "QHB_OFF_1" && columnIndex == this.tableTitle.length) {
          return "background: #F98E95;padding:0;color:black";
        } else if (row.color9 == "QHB_OFF_2" && columnIndex == this.tableTitle.length) {
          return "background: #FABCBE;padding:0;color:black";
        }
        if (row.areaName == "杭州") {
          return "font-weight:bold;color:black;padding:0;";
        }
        return "color:black;padding:0";
    },
    // 获取码号收入整体趋势
    getData() {
      stepUnitgrouth({
        cycleValue: this.searchData.acctMonth,
        areaId: this.searchData.areaId,
      }).then((res) => {
        if (res.code == 200) {
          res.data.tableMsg.map((item) => {
            if (item.code == "msg1") {
              this.monthFrom = item.msg;
            } else if (item.code == "msg2") {
              this.increaseFrom = item.msg;
            } else if (item.code == "msg3") {
              this.downFrom = item.msg;
            } else if (item.code == "msg4") {
              this.allFrom = item.msg;
            } else if (item.code == "msg5") {
              this.downText = item.msg;
            } else if (item.code == "msg6") {
              this.downThree = item.msg;
            } else if (item.code == "msg7") {
              this.allBudget = item.msg;
            } else if (item.code == "msg8") {
              this.frontBudget = item.msg;
            } else {
              this.laterBudget = item.msg;
            }
          });
          this.tableTitle = res.data.tableTitle.slice(
            1,
            res.data.tableTitle.length
          );
          this.tableData = res.data.tableData;
        }
      });
    },
    headerStyle({ row, column, rowIndex, columnIndex }) {
        if (
          columnIndex == this.tableTitle.length ||
          columnIndex == this.tableTitle.length - 1 ||
          columnIndex == this.tableTitle.length - 2 ||
          columnIndex == this.tableTitle.length - 3
        ) {
          return "background: #4BACC6;color: #000000;padding: 0;height: 26px;";
        }
      return "background: #FFC000;color: #000000;padding: 0;height: 26px;";
    },
  },
};
</script>

<style scoped>
.businessUnit {
  box-sizing: border-box;
  padding: 20px;
  box-shadow: 0px 0px 10px 1px rgb(0 0 0 / 15%);
}
</style>

<style scoped lang="scss">
.businessUnit {
  margin-top: 20px;
}
.connet {
  width: 100%;
  box-sizing: border-box;
  padding: 0 20px;
  margin-top: 10px;
  .text {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    .cont {
      font-size: 24px;
      line-height: 44px;
      display: flex;
    }
    .square {
      margin-top: 15px;
      margin-right: 15px;
      width: 10px;
      height: 10px;
      background: #c00000;
      transform: rotate(45deg);
    }
    .value {
      flex: 1;
      flex-wrap: wrap;
    }
    p {
      display: flex;
      align-items: center;
      padding-left: 40px;
      font-size: 20px;
      .circle {
        width: 4px;
        height: 4px;
        background-color: #c0504d;
        border-radius: 50%;
        display: inline-block;
        margin-right: 10px;
      }
    }
  }
  .table {
    width: 100%;
  }
  /deep/ .el-table {
    width: 100%;
  }
}
</style>
